package com.lhy.framework.context.annotation;

import cn.hutool.core.util.ClassUtil;
import com.lhy.framework.beans.factory.factory.BeanDefinition;
import com.lhy.framework.stereotype.Component;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * @Title:
 * @Description: 功能概述:
 * @Author: lihaiyang
 * @version: 1.0 .
 * @Date: 2022-09-14 10:48
 * @Copyright: Copyright(c)2022 RedaFlight.comAll Rights Reserved
 */
public class ClassPathScanningCandidateComponentProvider {

    public Set<BeanDefinition> findCandidateComponents(String basePackage) {

        Set<BeanDefinition> candidates = new LinkedHashSet<>();
        Set<Class<?>> classes = ClassUtil.scanPackageByAnnotation(basePackage, Component.class);
        for (Class<?> clazz : classes) {
            candidates.add(new BeanDefinition(clazz));
        }
        return candidates;
    }
}
